using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Member_Shop_Account : Member, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected Literal UserBalance;
	protected Literal LiteralFreezeMoney;
	protected Literal UserActiveBalance;
	protected PlaceHolder UserActiveBalancePanel;
	protected TextBox TxtCardNum;
	protected TextBox TextCardPassword;
	protected Label Lablefterro;
	protected Button Button1;
	protected TextBox TxtMoney;
	protected Button button3;
	protected Literal txtAllEp;
	protected Literal txtTransparent;
	protected TextBox txtEpCount;
	protected Button btTransparent;
	protected DropDownList DropType;
	protected TextBox begindate;
	protected TextBox EndDate;
	protected Button sb;
	protected GridView GridView1;
	private UserBll _user = null;
	private AccountDetailsBll _payment = null;
	private string wherestr = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected UserBll m_user
	{
		get
		{
			UserBll user;
			if (this._user == null)
			{
				this._user = new UserBll(this.conn);
				user = this._user;
			}
			else
			{
				user = this._user;
			}
			return user;
		}
	}
	protected AccountDetailsBll m_payment
	{
		get
		{
			AccountDetailsBll payment;
			if (this._payment == null)
			{
				this._payment = new AccountDetailsBll(this.conn);
				payment = this._payment;
			}
			else
			{
				payment = this._payment;
			}
			return payment;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.GridView1.PageIndexChanging += new GridViewPageEventHandler(this.GridView1_PageIndexChanging);
		if (!base.IsPostBack)
		{
			this.BindPayment();
			this.UserBalance.Text = base.user.Balance.ToString();
			this.ShowFreezeMoney();
			decimal d = 0m;
			try
			{
				d = (decimal)this.conn.GetScalar("Select sum(cMoney) from HL_AccountDetails Where UserID=" + base.user.UserID + " and cType=-1", new IDbDataParameter[0]);
			}
			catch
			{
			}
			if (d > 0m)
			{
				this.UserActiveBalancePanel.Visible = true;
			}
			this.UserActiveBalance.Text = d.ToString();
			this.txtAllEp.Text = base.user.UserEP.ToString();
			SiteConfigBll siteConfigBll = new SiteConfigBll();
			this.txtTransparent.Text = siteConfigBll.GetSiteString("SiteConfigInfo/TransparentScope");
			siteConfigBll.Dispose();
		}
		this.begindate.Attributes.Add("onclick", "SelectDate(" + this.begindate.UniqueID + ",'yyyy-MM-dd');");
		this.EndDate.Attributes.Add("onclick", "SelectDate(" + this.EndDate.UniqueID + ",'yyyy-MM-dd');");
	}
	public void ShowFreezeMoney()
	{
		DataTable dataTable = this.conn.GetDataTable("select FreezeMoney from  HL_User where UserID=" + base.user.UserID);
		if (dataTable.Rows[0]["FreezeMoney"].ToString() == "0.00")
		{
			this.LiteralFreezeMoney.Text = "0.00";
		}
		else
		{
			this.LiteralFreezeMoney.Text = dataTable.Rows[0]["FreezeMoney"].ToString();
		}
	}
	protected decimal get()
	{
		DataTable paymentByUserID = this.m_payment.GetPaymentByUserID(base.user.UserID);
		return (decimal)paymentByUserID.Rows[0]["cMoney"];
	}
	private void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GridView1.PageIndex = e.NewPageIndex;
		this.BindPayment();
	}
	protected void BindPayment()
	{
		if (this.wherestr != string.Empty)
		{
			this.GridView1.DataSource = this.m_payment.SearchPayment(this.wherestr);
			this.GridView1.DataBind();
		}
		else
		{
			this.GridView1.DataSource = this.m_payment.GetPaymentByUserID(base.user.UserID);
			this.GridView1.DataBind();
		}
	}
	protected void QuestString()
	{
		this.wherestr = "and UserID=" + base.user.UserID + " ";
		string selectedValue = this.DropType.SelectedValue;
		if (selectedValue != "")
		{
			if (selectedValue == "1")
			{
				this.wherestr += "and cType=1 ";
			}
			else
			{
				if (selectedValue == "0")
				{
					this.wherestr += "and cType=0 ";
				}
				else
				{
					this.wherestr += "and cType=-1 ";
				}
			}
		}
		string text = this.begindate.Text;
		if (text != string.Empty)
		{
			try
			{
				Convert.ToDateTime(text);
			}
			catch
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			this.wherestr = this.wherestr + "and datediff(dd,CreateTime,'" + text + "')<=0 ";
		}
		string text2 = this.EndDate.Text;
		if (text2 != string.Empty)
		{
			try
			{
				Convert.ToDateTime(text2);
			}
			catch
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			if (!string.IsNullOrEmpty(text) && Convert.ToDateTime(text2) < Convert.ToDateTime(text))
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
			}
			this.wherestr = this.wherestr + "and datediff(dd,CreateTime,'" + text2 + "')>=0 ";
		}
		if (this.wherestr != string.Empty)
		{
			this.wherestr = "and" + this.wherestr;
			this.wherestr = this.wherestr.Replace("andand", "where");
		}
	}
	protected void DropType_Onchange(object sender, EventArgs e)
	{
		this.QuestString();
		this.BindPayment();
	}
	protected void Search_OnClick(object sender, EventArgs e)
	{
		this.QuestString();
		this.BindPayment();
	}
	protected void Button1_Click(object sender, EventArgs e)
	{
		if (this.TxtCardNum.Text == "")
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Voucher/CardEmpty", new string[0]), "");
		}
		if (this.TextCardPassword.Text == "")
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Voucher/CardPassEmpty", new string[0]), "");
		}
		int num = this.m_user.UpdateUserCard(this.TxtCardNum.Text, this.TextCardPassword.Text, base.user.UserID, base.user.UserName);
		if (num != 0)
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Voucher/VoucherFail", new string[]
			{
				"000" + num
			}), "");
		}
		else
		{
			this.WriteSuccessMsg("", Language.GetMemberMsg("Voucher/VoucherSuccess", new string[0]), "");
		}
	}
	protected void Transparent_Click(object sender, EventArgs e)
	{
		if (this.txtEpCount.Text.Trim().Length < 1)
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Voucher/EpEmpty", new string[0]), "");
		}
		else
		{
			int i = 0;
			try
			{
				i = Convert.ToInt32(this.txtEpCount.Text.Trim());
			}
			catch
			{
				this.WriteErrMsg("", Language.GetMemberMsg("Voucher/EPErr", new string[0]), "");
				return;
			}
			int userEP = base.user.UserEP;
			if (i > userEP)
			{
				i = userEP;
			}
			int num = Convert.ToInt32(this.txtTransparent.Text);
			if (i < num)
			{
				this.WriteErrMsg("", Language.GetMemberMsg("Voucher/EpFail", new string[0]), "");
			}
			else
			{
				int num2 = 0;
				while (i >= num)
				{
					i -= num;
					num2++;
				}
				base.user.Balance += num2;
				base.user.UserEP -= num2 * num;
				UserBll userBll = new UserBll(this.conn);
				bool flag = userBll.UpdateUserScope(base.user.UserID, base.user.Balance, base.user.UserEP);
				if (flag)
				{
					this.txtAllEp.Text = base.user.UserEP.ToString();
					UserExpAction userExpAction = new UserExpAction(this.conn);
					userExpAction.AddUserExp(base.user.UserID, (long)(-(long)(num2 * num)), 5, Language.Get("PassPort/TranspanretExp"), new Conn[0]);
					this.WriteSuccessMsg("", Language.GetMemberMsg("Voucher/EpSuccess", new string[0]), "Shop_Account.aspx");
				}
				else
				{
					this.WriteErrMsg("", Language.GetMemberMsg("Voucher/EpFail", new string[0]), "");
				}
			}
		}
	}
}
